package com.cs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.cs.domain.CSCategory;
import com.cs.service.ICsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 物料分类Controller
 * 
 * @author ruoyi
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/category")
public class CsCategoryController extends BaseController
{
    @Autowired
    private ICsCategoryService csCategoryService;

    /**
     * 查询物料分类列表
     */
    @RequiresPermissions("system:category:list")
    @GetMapping("/list")
    public TableDataInfo list(CSCategory csCategory)
    {
        startPage();
        List<CSCategory> list = csCategoryService.selectCsCategoryList(csCategory);
        return getDataTable(list);
    }

    /**
     * 导出物料分类列表
     */
    @RequiresPermissions("system:category:export")
    @Log(title = "物料分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CSCategory csCategory)
    {
        List<CSCategory> list = csCategoryService.selectCsCategoryList(csCategory);
        ExcelUtil<CSCategory> util = new ExcelUtil<CSCategory>(CSCategory.class);
        util.exportExcel(response, list, "物料分类数据");
    }

    /**
     * 获取物料分类详细信息
     */
    @RequiresPermissions("system:category:query")
    @GetMapping(value = "/{cId}")
    public AjaxResult getInfo(@PathVariable("cId") Long cId)
    {
        return success(csCategoryService.selectCsCategoryByCId(cId));
    }

    /**
     * 新增物料分类
     */
    @RequiresPermissions("system:category:add")
    @Log(title = "物料分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CSCategory csCategory)
    {
        return toAjax(csCategoryService.insertCsCategory(csCategory));
    }

    /**
     * 修改物料分类
     */
    @RequiresPermissions("system:category:edit")
    @Log(title = "物料分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CSCategory csCategory)
    {
        return toAjax(csCategoryService.updateCsCategory(csCategory));
    }

    /**
     * 删除物料分类
     */
    @RequiresPermissions("system:category:remove")
    @Log(title = "物料分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cIds}")
    public AjaxResult remove(@PathVariable Long[] cIds)
    {
        return toAjax(csCategoryService.deleteCsCategoryByCIds(cIds));
    }

    /**
     * 获得级联
     * @return
     */
    @GetMapping("/getLevel")
    public AjaxResult getLevel(){
        return success(csCategoryService.getLevel());
    }
}